{include file='public/meta'}
<title>管理员管理 - 管理员列表 - 木鱼内容管理系统</title>
<style>
  .form1 {
      display: flex;
  }
  </style>
</head>
<body>
	<div class="layui-fluid">
		<div class="layui-card">
			<div class="layui-form layui-card-header layuiadmin-card-header-auto">
				<div class="layui-form-item">
				    
					<div class="layui-inline">
                        <label class="layui-form-label">管理员查找</label>
                        <div class="layui-input-block">
                          <input type="text" name="keywords" id="keywords" placeholder="请输入关键词" class="layui-input">
                        </div>
                      </div>
					<div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin" onclick="so()" type="submit">
                      <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                  </div>
				</div>
			</div>

			<div class="layui-card-body">
				<div style="padding-bottom: 10px;">
					<a class="layui-btn layui-btn-danger layuiadmin-btn-admin" onclick="delAll()">批量删除</a>
					<a class="layui-btn layuiadmin-btn-admin" onclick="openwind('添加管理员','{:url('Admin/add')}')">添加</a>
				</div>
            <div class="layui-table-body layui-table-main">
                <table class="layui-table" id="LAY-user-front-submit">
					<thead>
						<tr>
							<th class=" layui-table-col-special">
							    <div class="layui-table-cell laytable-cell-checkbox">
							        <input type="checkbox" id="checkAll" onclick="isCheck()">
							    </div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>ID</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>用户名</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>邮箱</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>手机号码</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>角色</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>创建时间</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>状态</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>操作</span></div>
							</th>
						</tr>
					</thead>
					<tbody>
					    {foreach $admin as $val}
						<tr align="center">
							<td class="layui-table-col-special">
								<input type="checkbox" name="fav" value="{$val.id}">
							</td>
							<td>{$val.id}</td>
							<td>{$val.name}</td>
							<td>{$val.email}</td>
							<td>{$val.phone}</td>
							{if condition="!empty($val['rolesname'])"}
							<td>
							{$val['rolesname']}
							</td>
							{else /}
							<td>无</td>
							{/if}
							<td>{:date("Y-m-d",$val.create_time)}</td>
							<td><div class="layui-table-cell">
                                      <a class="layui-btn-xs layui-btn layui-btn-{php}echo $val['status']=='已启用' ? 'btn' : 'danger';{/php}">{$val.status}</a>
                                </div>
                            </td>
                            
							<td align="center" data-off="true" class="layui-table-col-special">
								<div class="layui-table-cell">
									<a class="layui-btn layui-btn-normal layui-btn-xs" onclick="openwind('管理员编辑','{:url('Admin/edit',['id'=>$val.id])}')"><i class="layui-icon layui-icon-edit"></i>编辑</a>
									{if ($val.center == 1)}
									<a class="layui-btn layui-btn-{if $val['status'] == '已启用'/}danger{else/}xs{/if} layui-btn-xs" onclick="setStatus({$val.id})" href="javascript:;"><i class="layui-icon layui-icon-radio"></i>{php}echo $val['status']=='已启用' ? '停用' : '启用';{/php}</a>
									<a class="del layui-btn layui-btn-danger layui-btn-xs" onclick="del('{$val.id}')"><i class="layui-icon layui-icon-delete"></i>删除</a>
									{/if}
								</div>
							</td>
						</tr>
						{/foreach}
					</tbody>
				</table>
            </div>
                <div class="layui-box layui-laypage layui-laypage-molv">{$admin|raw}</div>
			</div>

		</div>
	</div>


	<!-- 低部区域 -->
	{include file='public/footer'}
	<script>
		layui.config({
			base: '__ADMINST__layuiadmin/' //静态资源所在路径
				,
			version: new Date().getTime()
		}).extend({
			index: 'lib/index' //主入口模块
		}).use(['index', 'table']);
		
		    // 全选 页面调用
            function isCheck(){
                var IsCheck= document.getElementById("checkAll");
                if(IsCheck.checked==false){
                    var groupC= document.getElementsByName("fav");
                    for(var i=0;i<groupC.length;i++){
                        groupC[i].checked=false;
                    }
                }
                if (IsCheck.checked==true) {
                    var groupC= document.getElementsByName("fav");
                    for(var i=0;i<groupC.length;i++){
                        groupC[i].checked=true;
                    }
                }
            }
    
        //删除操作
        function del(id){
            	layer.msg('确认删除？', {
				time: 5000, //5s后自动关闭
				shade: 0.3,
				btn: ['确认', '取消'],
				yes: function() {
					//执行删除
					$.post("{:url('Admin/deletes')}", {id: id}, function(data) {
					    if(data.code === 1){
					        layer.msg(data.msg, {time: 2000}, function() {
							if (data.url) location.href = data.url;
						    });
					    }else{
					        layer.msg(data.msg, {time: 2000});
					    }
					})
				}
			});
        }
        
        //批量删除
        function delAll(){
            var id=$("tbody input:checkbox");
    		var ids=[];
    		for(i=0;i<id.length;i++){
    			if($(id[i]).is(":checked")){
    				ids += $(id[i]).val()+',';
    			}
    		}
    		var delid = ids;
    		if(delid == ""){
    			layer.msg('当前未选择任何信息!',{icon:2,time:2000});
    		}else{
    		    layer.msg('确认删除？', {
				time: 5000, //5s后自动关闭
				shade: 0.3,
				btn: ['确认', '取消'],
				yes: function() {
					//执行删除
					$.post("{:url('Admin/deletes')}", {id: delid}, function(data) {
					    if(data.code === 1){
					        layer.msg(data.msg, {time: 2000}, function() {
							if (data.url) location.href = data.url;
						    });
					    }else{
					        layer.msg(data.msg, {time: 2000});
					    }
					})
				}
			});
    		}
        }
        
        //状态变更
        function setStatus(id){
                layer.msg('确认要变更状态吗？', {
				time: 5000, //5s后自动关闭
				shade: 0.3,
				btn: ['确认', '取消'],
				yes: function() {
					//执行变更
					$.post("{:url('Admin/setStatus')}",{id:id}, function(data) {
					    if(data.code === 1){
					        layer.msg(data.msg, {time: 2000}, function() {
							if (data.url) location.href = data.url;
						    });
					    }else{
					        layer.msg(data.msg, {time: 2000});
					    }
					})
    			   }
    			});
		}
		
		//搜索操作
		function so(){
		    var keywords = $("#keywords").val();
		    if(keywords == ""){
		        layer.msg("请输入搜索内容!", {time: 2000});
		    }else{
		        layer.open({
    		    title:"搜索内容",
                type: 2, 
                area:['100%','100%'],
                content: "{:url('Admin/search')}"+"?keywords="+keywords,
                end:function(){
    			    location.reload();
    			    }
                }); 
		    }
		    
		}
		function updateadmin(){
			var D,mdid;
			mdid = $("#adminid").val();
			if(!/^\s*$/g.test(mdid)){
				D={admid:mdid};
				$.ajax({
				    type: 'POST',
				    url: '{:url("admin/Admin/updateadmin")}',
					data: D,
				    dataType: "json",
				    beforeSend: function() {
				        index = layer.load();
				    },
				    success: function(data) {
				        layer.msg(data.msg, {time: 2000}, function() {
				            location.reload();
				        });
				    },
				    complete: function() {
				        layer.close(index);
				    }
				});
			}else{
				layer.msg("请选择一个作为初始管理的账户!");
			}
		}

	</script>
</body>
</html>
